#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fb.h>

int main(int argc, char *argv[])
{
    struct fb_var_screeninfo fb_var;
    struct fb_fix_screeninfo fb_fix;
    int fd;

    if ((fd = open("/dev/fb0", O_WRONLY)) < 0) {
        perror("open error");
        exit(EXIT_FAILURE);
    }

    /* 获取屏幕参数信息 */
    ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
    ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix);

    printf("分辨率 %d x %d \n"
           "像素深度bpp %d \n"
           "一行字节数：%d \n"
           "像素格式 R<%d %d>, G<%d %d>, B<%d %d>\n",
            fb_var.xres, fb_var.yres,
            fb_var.bits_per_pixel,
            fb_fix.line_length,
            fb_var.red.offset, fb_var.red.length,
            fb_var.green.offset, fb_var.green.length,
            fb_var.blue.offset, fb_var.blue.length);

    close(fd);
    exit(EXIT_SUCCESS);
}
